package com.gd.client.service;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

import com.gd.client.action.*;
import com.gd.common.net.*;



public class ClientThread extends Thread{
	private Socket s;
	private ObjectInputStream ois;
	private ObjectOutputStream oos;

	
	public  ClientThread(Socket s){
		
		this.s=s;
		try {
			ois=new ObjectInputStream(s.getInputStream());
			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void run(){
		RequestToClient request=null;
		
		try {
			request=(RequestToClient)ois.readObject();
		
		
			ClientAction action=null;
	
			ClientContext clientContext=ClientContext.NewClientContext();
			Class c=Class.forName(clientContext.getActionNameByRequestCode(request.getType()));
	
			action=(ClientAction)c.newInstance();
		
			action.execute(request);
		
		
			
		
		} catch (Exception e) {
			e.printStackTrace();
		} 
	}

}
